# from py2neo import Graph, Node
# import json

# # Neo4j 连接信息
# NEO4J_URI = "bolt://localhost:7687"
# NEO4J_USER = "neo4j"
# NEO4J_PASSWORD = "123456"

# def node_to_dict_with_Id(node: Node):
#     return {
#         "identity": node.identity,
#         "labels": list(node.labels),
#         "properties": dict(node)
#     }

# def get_drawing_final_inspection(drawing_id):
#     """查询指定图纸ID的终检信息并返回处理后的列表"""
#     # 连接数据库
#     graph = Graph(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))
    
#     # 执行查询
#     cypher_query = """
#     MATCH (d:图纸 {图纸ID: $drawing_id})-[:有终检项]->(fi:终检)
#     RETURN fi AS 终检
#     """
#     result = graph.run(cypher_query, drawing_id=drawing_id)
    
#     # 处理结果并返回列表
#     return [node_to_dict_with_Id(record["终检"]) for record in result]

# # 测试用例：如果直接运行脚本则保存到文件（仅测试用）
# if __name__ == "__main__":
#     drawing_id = "2c9212b3958edc700195cafc96316b85"
#     results = get_drawing_final_inspection(drawing_id)
    
#     # 测试时保存到当前目录的jsonl文件
#     with open("final_inspections.jsonl", "w", encoding="utf-8") as f:
#         for item in results:
#             json.dump(item, f, ensure_ascii=False)
#             f.write("\n")
    
#     print(f"测试保存完成，共 {len(results)} 条记录")
